package com.semanticweb.project.search.analyzer.filters;

import java.io.IOException;

import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;

public class CyrilicToLatinFilter extends TokenFilter {

	private final CharTermAttribute termAttribute;
	
	public CyrilicToLatinFilter(final TokenStream input) {
		super(input);
		termAttribute = (CharTermAttribute) input.addAttribute(CharTermAttribute.class);
	}
	
	public boolean incrementToken() throws IOException {
		if (input.incrementToken()) {
			final String text = termAttribute.toString();
			termAttribute.setEmpty();
			termAttribute.append(CyrilicLatinConverter.cir2lat(text));
			return true;
		}
		return false;
	}
}